const start = ref(-1);
const end = ref(-1);
const group_name = ref('');
export default (
  group: string,
  callback: (...args) => void,
  genOptions?: (record: Obj) => Obj,
) => {
  const customRow = (_record, index) => {
    return {
      style: {
        cursor: 'grab',
      },
      ...(genOptions ? genOptions(_record) : {}),
      draggable: true,
      onDragstart: e => {
        e.stopPropagation();
        start.value = index;
        group_name.value = group;
      },
      onDragover: e => {
        if (group_name.value == group) {
          e.preventDefault();
        } else {
          return false;
        }
      },
      onDrop(e) {
        if (group_name.value == group) {
          e.stopPropagation();
          end.value = index;
          callback(start.value, end.value);
        }
      },
    };
  };
  return {
    customRow,
  };
};
